package com.lantosec.hmrp.modules.internal.controller;


import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import com.lantosec.hmrp.modules.internal.entity.InternalPlanList;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.internal.entity.InternalPlan;
import com.lantosec.hmrp.modules.internal.service.IInternalPlanService;
import com.lantosec.hmrp.modules.internal.vo.InternalPlanVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 评价方案 控制器
 *
 * @author AutoCode
 * @since 2020-04-23
 */
@Api(value = "评价方案控制器", tags = "评价方案控制器")
@RestController
@RequestMapping("/internal/plan")
@Log4j2
public class InternalPlanController extends BaseController {
    @Autowired
    private IInternalPlanService service;

    @GetMapping("all")
    @ApiOperation(value = "查询全部")
    public Result<List<InternalPlanVO>> all(){
        return Result.ok(entity2VO(service.list()));
    }

    @GetMapping("getInternalPlanInfo")
    @ApiOperation(value = "查询考评方案详情")
    public Result<InternalPlanVO> getInternalPlanInfo(@ApiParam(value = "考评方案ID",required = true) @RequestParam(name = "internalPlanId")Integer internalPlanId){
        InternalPlanVO internalPlanVO = service.getInternalPlanVo(internalPlanId);
        return Result.ok(internalPlanVO);
    }

    @GetMapping("page")
    @ApiOperation(value = "分页查询")
    public Result<Page<InternalPlanVO>> page(@ApiParam(value = "分页对象", required = true) PageVO<InternalPlan> page,
                                             @ApiParam(value = "考评方案名称") @RequestParam(name = "internalPlanName",required = false) String internalPlanName,
                                             @ApiParam(value = "考评方案类型") @RequestParam(name = "internalPlanType",required = false) Integer internalPlanType){
        PageVO<InternalPlanVO> pageVO = service.getAll(page,internalPlanName,internalPlanType);
        return Result.ok(pageVO);
    }

    @GetMapping("get/{id}")
    @ApiOperation(value = "主键查询")
    public Result<InternalPlanVO> get(@ApiParam(value = "ID", required = true) @PathVariable(name="id") String id){
        return Result.ok(entity2VO(service.getById(id)));
    }

    @PostMapping("create")
    @ControllerLog(name = "新增内部满意度评价方案", type = LogType.add)
    @ApiOperation(value = "新增内部满意度评价方案")
    public Result<Integer> create(@ApiParam(value = "评价方案VO对象", required = true) @RequestBody @Validated InternalPlanList internalPlanList){
        Integer internalPlanId = service.saveInternalPlan(internalPlanList);
        return Result.ok(internalPlanId);
    }

    @PutMapping("update")
    @ControllerLog(name = "复制新增内部满意度评价方案", type = LogType.add)
    @ApiOperation(value = "复制新增内部满意度评价方案")
    public Result<Void> update(@ApiParam(value = "评价方案VO对象", required = true) @RequestBody InternalPlanList internalPlanList){
        service.updateInternalPlan(internalPlanList);
        return Result.ok();
    }

    @PutMapping("updateParam")
    @ControllerLog(name = "修改内部满意度考评方案基本信息", type = LogType.update)
    @ApiOperation(value = "修改内部满意度考评方案基本信息")
    public Result<Void> updateParam(@ApiParam(value = "评价方案VO对象", required = true) @RequestBody InternalPlan internalPlan){
        service.updateById(internalPlan);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{internalPlanId}")
    @ControllerLog(name = "逻辑删除内部满意度考评方案基本信息", type = LogType.delete)
    @ApiOperation("逻辑删除内部满意度考评方案基本信息")
    public Result<Void> delete(@ApiParam(value = "ID", required = true) @PathVariable(name="internalPlanId") Integer internalPlanId){
        service.deleteInternalPlan(internalPlanId);
        return Result.ok();
    }
}
